package com.mnb.beidou.config;

import java.util.HashMap;
import java.util.Map;

/**
 * 参数解析规则配置，基于《水位及气象数据采集1.docx》的参数表
 */
public class ParamRuleConfig {
    // 功能码映射表（基于《PS+MODBUS协议用户版V0.1(1).pdf》）
    public static final Map<String, String> FUNCTION_CODES = new HashMap<>();
    public static final Map<Integer, ParamRule> PARAM_RULES = new HashMap<>();

    static {
        // 初始化功能码说明
        FUNCTION_CODES.put("04", "读模拟量寄存器");
        FUNCTION_CODES.put("02", "读开关量输入状态");
        FUNCTION_CODES.put("05", "控制继电器输出成功");
        FUNCTION_CODES.put("03", "读保持寄存器（参数区）");
        FUNCTION_CODES.put("10", "写多个保持寄存器（参数区）");
        FUNCTION_CODES.put("2C", "主动上报数据");
        FUNCTION_CODES.put("2D", "召测历史记录");
        FUNCTION_CODES.put("3A", "主动上报历史记录（下行含校时）");
        FUNCTION_CODES.put("3B", "主动上报事件记录（下行含校时）");
        // 初始化参数规则，包含参数名汉字描述
        PARAM_RULES.put(35001, new ParamRule("radarWaterLevel", "雷达水位", 2, false, 2, "m"));
        PARAM_RULES.put(35003, new ParamRule("radarEmptyHeight", "雷达空高", 2, false, 2, "m"));
        PARAM_RULES.put(35005, new ParamRule("pressureWaterLevel", "压力水位", 2, false, 2, "m"));
        PARAM_RULES.put(35007, new ParamRule("currentRainfall", "当前雨量", 1, false, 1, "mm"));
        PARAM_RULES.put(35008, new ParamRule("totalRainfall", "累计雨量", 2, false, 1, "mm"));
        PARAM_RULES.put(35010, new ParamRule("temperature", "温度", 2, true, 2, "℃"));
        PARAM_RULES.put(35012, new ParamRule("humidity", "湿度", 2, true, 2, "%RH"));
        PARAM_RULES.put(35014, new ParamRule("atmosphericPressure", "大气压", 2, false, 2, "Kpa"));
        PARAM_RULES.put(35016, new ParamRule("dopplerWaterLevel", "多普勒水位", 2, false, 2, "m"));
        PARAM_RULES.put(35018, new ParamRule("instantaneousFlow", "瞬时流量", 2, false, 2, "m³/s"));
        PARAM_RULES.put(35020, new ParamRule("totalFlow", "累计流量", 2, false, 0, "m³"));
        PARAM_RULES.put(35022, new ParamRule("powerVoltage", "电源电压", 1, false, 2, "V"));
        PARAM_RULES.put(35023, new ParamRule("signalQuality", "信号质量", 1, false, 0, "dB"));
        PARAM_RULES.put(35028, new ParamRule("dopplerTemperature", "多普勒温度", 2, true, 2, "℃"));
        PARAM_RULES.put(35030, new ParamRule("flowVelocity", "流速", 2, false, 2, "m/s"));
    }

    public static class ParamRule {
        String fieldName;      // 实体类字段名
        String chineseName;    // 参数名汉字描述
        int regCount;          // 寄存器数量（文档1中的“寄存器数量”）
        boolean isSigned;      // 是否有符号（文档1中的“格式”）
        int decimalPlaces;     // 小数位数（文档1中的“小数位数”）
        String unit;           // 单位符号

        public ParamRule(String fieldName, String chineseName, int regCount, boolean isSigned, int decimalPlaces, String unit) {
            this.fieldName = fieldName;
            this.chineseName = chineseName;
            this.regCount = regCount;
            this.isSigned = isSigned;
            this.decimalPlaces = decimalPlaces;
            this.unit = unit;
        }

        // getter方法
        public String getFieldName() {
            return fieldName;
        }

        public String getChineseName() {
            return chineseName;
        }

        public int getRegCount() {
            return regCount;
        }

        public boolean isSigned() {
            return isSigned;
        }

        public int getDecimalPlaces() {
            return decimalPlaces;
        }

        public String getUnit() {
            return unit;
        }
    }


//    public static class functionCode {
//        String functionCode;      // 功能码
//        String functionDes;    // 功能描述
//
//        public functionCode(String functionCode, String functionDes) {
//            this.functionCode = functionCode;
//            this.functionDes = functionDes;
//        }
//
//        // getter方法
//        public String getFunctionCode() {
//            return functionCode;
//        }
//
//        public String getFunctionDes() {
//            return functionDes;
//        }
//    }


}